<!DOCTYPE html>
<!--
==========================================================================
LV自动生成列表页面代码,只生成一次,按需修改.
生成日期：2024-02-28 14:21:50 +0800 CST
生成路径: template/mywork/params/list.html
生成人：lv
==========================================================================
-->
<html lang="zh">
<head>
    {{template "header" (OssUrl)}}
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <p>启用状态：</p>
                            <select name="useFlag">
                                <option value="">所有</option>
                                <option value="0">未启用</option>
                                <option value="1">已启用</option>
                            </select>
                        </li>
                        <li>
                            <p>参量类型：</p>
                            <select name="paramType">
                                <option value="">所有</option>
                                <option value="ai">遥测（AI）</option>
                                <option value="di">遥信（DI）</option>
                                <option value="ao">遥调（AO）</option>
                                <option value="do">遥控（DO）</option>
                            </select>
                        </li>
                        <li>
                            <p>参量名称：</p>
                            <input type="text" name="paramName"/>
                        </li>


                        <li>
                            <p>监控类型：</p>
                            <input type="text" name="monitorTypeId"/>
                        </li>
                        <li>
                            <p>备注信息：</p>
                            <input type="text" name="remark"/>
                        </li>
                        <li>
                            <p>参量范围：</p>
                            <input type="text"  name="paramNoStart" placeholder="最小参量号"/>
                            <span>~</span>
                            <input type="text"  name="paramNoEnd" placeholder="最大参量号"/>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            {{PermButton .uid "mywork:params:add" "showPrompt()" "生成10个参量号" "btn btn-success" "fa fa-plus"}}
            {{PermButton .uid "mywork:params:edit" "$.operate.editFull()" "修改" "btn btn-primary single disabled" "fa fa-edit"}}
            {{PermButton .uid "mywork:params:remove" "$.operate.removeAll()" "删除" "btn btn-danger multiple disabled" "fa fa-remove"}}
            {{PermButton .uid "mywork:params:export" "$.table.exportExcel()" "导出" "btn btn-warning" "fa fa-download"}}
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
{{template "footer" (OssUrl)}}
<script src="{{OssUrl}}/resource/js/jquery.tmpl.js"></script>
<script type="text/javascript">
    var editFlag = '{{HasPerm .uid "mywork:params:edit"}}';
    var removeFlag = '{{HasPerm .uid "mywork:params:remove"}}';

                      
    var prefix = ctx + "/mywork/params";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit?id={id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            sortName:"paramNo",
            sortOrder:"desc",
            modalName: "基础参量管理",
            columns: [
                {
                    checkbox: true
                },  
                {
                    field: 'id',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'paramNo',
                    width: "40",
                    title: '参量号'
                },
                {
                    field: 'monitorTypeId',
                    width: "5",
                    title: '监控类型',
                    formatter: function (value, row, index) {
                        let html = value
                        if(row.useFlag=="0"){
                            let str = "<input onblur=\"autoSave(this,'%s')\" class='form-control' type='text' name='columns[%s].monitorTypeId' value='%s' required>"
                            html = $.common.sprintf(str,row.id,index, value);
                        }
                        return html
                    }
                },
                {
                    field: 'paramName',
                    width: "300",
                    title: '参量名称',
                    formatter: function (value, row, index) {
                        let html = value
                        if(row.useFlag=="0"){
                            let str = "<input onblur=\"autoSave(this,'%s')\" class='form-control' type='text' name='columns[%s].paramName' value='%s' required>"
                            html = $.common.sprintf(str,row.id,index, value);
                        }
                        return html
                    }
                },      
                {
                    field: 'paramType',
                    width: "100",
                    title: '参量类型',
                    formatter: function (value, row, index) {
                        let html = value
                        if(row.useFlag=="0"){
                            let data = [ {dictLabel: "请选择", dictValue: ""}
                                        ,{dictLabel: "ai", dictValue: "ai"}
                                        ,{dictLabel: "di", dictValue: "di"}
                                        ,{dictLabel: "ao", dictValue:  "ao"}
                                        ,{dictLabel: "do", dictValue:  "do"}];
                            return dictToSelect(data,row.id,value);
                        }
                        return html
                    }
                },      
                {
                    field: 'unit',
                    width: "60",
                    title: '单位',
                    formatter: function (value, row, index) {
                        let html = value
                        if(row.useFlag=="0"){
                            let str = "<input onblur=\"autoSave(this,'%s')\" class='form-control' type='text' name='columns[%s].unit' value='%s' required>"
                            html = $.common.sprintf(str,row.id,index, value);
                        }
                        return html
                    }
                },      
                {
                    field: 'remark',
                    title: '备注信息'
                    ,formatter: function (value, row, index) {
                        let str = "<input onblur=\"autoSave(this,'%s')\" class='form-control' type='text' name='columns[%s].remark' value='%s' required>"
                        let html = $.common.sprintf(str,row.id,index, value);
                        return html
                    }
                },
                {
                    field: 'useFlag',
                    width: "20",
                    title: '启用状态',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                // {
                //     title: '操作',
                //     width: "20",
                //     align: 'center',
                //     formatter: function (value, row, index) {
                //         var actions = [];
                //         // actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                //         actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                //         return actions.join('');
                //     }
                // }
            ]
        };
        $.table.init(options);
    });

    function paramTypeChanged(input,id){
        // let selectedValue = comp.options[comp.selectedIndex].value;
        // alert(id + "--" + selectedValue + comp.value)
        $.ajax({
            type: "post",
            url: prefix + "/changeProp",
            data: {
                "name": "paramType",
                "id": id,
                "value": input.value
            },
            success: function(r) {
                if (r.code == web_status.SUCCESS) {
                    $.modal.msgSuccess(r.msg)
                } else {
                    $.modal.msgError(r.msg);
                }
            }
        });
    }
    /* 用户状态显示 */
    function statusTools(row) {
        let html = ""
        if (row.useFlag == 0) {
            html = '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
        } else {
            html = '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
        }
        console.log("#######"+html)
        return html
    }
    /* 用户管理-停用 */
    function disable(id) {
        $.modal.confirm("确认要停用此参量吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"id": id, "status": "0"});
        })
    }
    /* 用户管理启用 */
    function enable(id) {
        $.modal.confirm("确认要启用用户吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"id": id, "status": "1"});
        })
    }

    function autoSave(input,id){
        console.log(input.name,'-===================--',input.value,'  id:',id)
        $.ajax({
            type: "post",
            url: prefix + "/changeProp",
            data: {
                "name": input.name,
                "id": id,
                "value": input.value
            },
            success: function(r) {
                if (r.code == web_status.SUCCESS) {
                    $.modal.msgSuccess(r.msg)
                } else {
                    $.modal.msgError(r.msg);
                }
            }
        });
    }

    function showPrompt(){
        let baseNum = 0;
        layer.prompt({title: '输入参量号的基数：', formType: 0}, function(inputVal, index){
            baseNum =inputVal;
            genParams(baseNum,10)
            layer.close(index);
        });
    }
    function genParams(baseNum,amount){
        $.ajax({
            type: "post",
            url: prefix + "/genParams",
            data: {
                "baseNum": baseNum,
                "amount": amount,
            },
            success: function(r) {
                if (r.code == web_status.SUCCESS) {
                    $.modal.msgSuccess(r.msg)
                } else {
                    $.modal.msgError(r.msg);
                }
            }
        });
    }
</script>

<script>


    function dictToSelect(datas,dataId,value) {
        let actions = [];
        actions.push("<select onchange=\"paramTypeChanged(this,"+dataId+")\" class='form-control'>");
        $.each(datas, function(index, dict) {
            actions.push("<option value='"+dict.dictValue+"'")
            if (dict.dictValue == ('' + value)) {
                actions.push(' selected');
            }
            actions.push(">"+ dict.dictLabel+"</option>")
        });
        actions.push('</select>');
        let html =  actions.join('');
        console.log("============="+html)
        return html
    }


</script>

<script>
    $(document).keydown(function (event) {
        if(event.keyCode == 13){
            $.table.search()
        }
    })
</script>
</body>
</html>